package org.jxkj.util

import org.apache.spark.SparkContext
import org.apache.spark.sql.SparkSession
import org.jxkj.app.MysqlDml
import org.jxkj.data.IDaoProvider
import org.jxkj.util.DftoMap.insertDF2H
import org.jxkj.utils.PointFormulaKit

import java.util.ArrayList
import java.util.List
object getDataToMap {


  def df2Map(ss: SparkSession, sc: SparkContext,statList:List[String], time: Array[String]): Map[String,Double] = {

    val startTime = time(0)
    val endTime = time(1)
    val dimension = "day"
    val pointset= PointFormulaKit.getSqlString(statList)
    val jdbcDF = ss.read
      .format("jdbc")
      .option("url", MysqlDml.url2)
      .option("dbtable", "hms_stat_caldata")
      .option("user", MysqlDml.user2)
      .option("password", MysqlDml.password2)
      .option("driver", MysqlDml.driver2)
      .load()
    jdbcDF.createOrReplaceTempView("hms_stat_caldata")

    val df = ss.sql(s"select point_code,calvalue from hms_stat_caldata where stat_type='$dimension' and stat_date between '$startTime' and '$endTime'")
    val data = df.rdd.map(x => (x.getAs[String]("point_code"), x.getAs[Double]("calvalue"))).collect().toMap[String, Double]
    return data
  }
}
